{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "from gensim.models import KeyedVectors\n",
    "# load words vector from external file\n",
    "cn_word_vecs = KeyedVectors.load_word2vec_format('sgns.zhihu.bigram', binary=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "# save words into a file\n",
    "with open('words.txt', 'w') as f:\n",
    "    for word in cn_word_vecs.vocab:\n",
    "        f.write(word.encode('utf-8') + '\\n')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "259883\n"
     ]
    }
   ],
   "source": [
    "# length of the words\n",
    "print len(cn_word_vecs.vocab.items())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "大连理工大学\n",
      "华南理工大学\n",
      "四川大学\n",
      "海南大学\n",
      "暨南大学\n",
      "兰州大学\n",
      "西安交通大学\n",
      "人民大学\n",
      "湖南大学\n",
      "大连理工\n"
     ]
    }
   ],
   "source": [
    "for word in cn_word_vecs.most_similar(u'东南大学'):\n",
    "    print word[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "图像识别\n",
      "机器翻译\n",
      "图像处理\n",
      "模式识别\n",
      "NLP\n",
      "分布式计算\n",
      "语言识别\n",
      "图形图像\n",
      "科学计算\n",
      "网络分析\n"
     ]
    }
   ],
   "source": [
    "for word in cn_word_vecs.most_similar(u'自然语言处理'):\n",
    "    print word[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "杰伦\n",
      "周董\n",
      "林俊杰\n",
      "陈奕迅\n",
      "潘玮柏\n",
      "华晨宇\n",
      "王菲\n",
      "王力宏\n",
      "许嵩\n",
      "容祖儿\n"
     ]
    }
   ],
   "source": [
    "for word in cn_word_vecs.most_similar(u'周杰伦'):\n",
    "    print word[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "美女\n",
      "靓女\n",
      "靓妹\n",
      "丑男\n",
      "帅小伙\n",
      "大美女\n",
      "小美女\n",
      "帅哥们\n",
      "美女吧\n",
      "帅锅\n"
     ]
    }
   ],
   "source": [
    "for word in cn_word_vecs.most_similar(u'帅哥'):\n",
    "    print word[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "持之以恒\n",
      "不懈\n",
      "锲而不舍\n",
      "孜孜不倦\n",
      "十年如一日\n",
      "数年如一日\n",
      "夜以继日\n",
      "不怕困难\n",
      "不屈不挠\n",
      "不懈努力\n"
     ]
    }
   ],
   "source": [
    "for word in cn_word_vecs.most_similar(u'坚持不懈'):\n",
    "    print word[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "锐利\n",
      "凌厉\n",
      "尖刻\n",
      "老辣\n",
      "一针见血\n",
      "切中要害\n",
      "机敏\n",
      "文笔流畅\n",
      "机智幽默\n",
      "精辟\n"
     ]
    }
   ],
   "source": [
    "for word in cn_word_vecs.most_similar(u'犀利'):\n",
    "    print word[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "早上\n"
     ]
    }
   ],
   "source": [
    "print cn_word_vecs.doesnt_match(u'乒乓球 篮球 足球 早上'.split())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}